<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>评论</title>
</head>
<script src="https://cdn.staticfile.org/axios/0.18.0/axios.min.js"></script>
<!-- 引入 layui.css -->
<link rel="stylesheet" href="//unpkg.com/layui@2.6.8/dist/css/layui.css">
<!-- 引入 layui.js -->
<script src="//unpkg.com/layui@2.6.8/dist/layui.js"></script>

<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">名字</label>
        <div class="layui-input-block">
            <input type="text" name="name" required lay-verify="required" placeholder="请输入名字" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">联系方式</label>
        <div class="layui-input-block">
            <input type="text" name="contact" required lay-verify="required" placeholder="请输入联系方式" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">留言内容</label>
        <div class="layui-input-block">
            <textarea name="content" placeholder="请输入留言内容" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script>
    //Demo
    layui.use(['form', 'layer'], function() {
        var form = layui.form;
        var layer = layui.layer;
        //监听提交
        form.on('submit(formDemo)', function(data) {
            var comment = data.field
            var content = '联系方式:' + comment.contact + '           ' + '内容:' + comment.content
            axios
                .post('https://api.dzzui.com/api/mail?Host=smtp.qq.com&Username=polarislovetop@qq.com&Password=pabqwbqicljmicfb&Port=465&SMTPSecure=ssl&addAddress=2283761246@qq.com&title=' + comment.name + '提交的评论' + '&text=' + content)
                .then(res => {

                })
                .catch(function(error) { // 请求失败处理
                    console.log(error);
                });
            layer.msg("留言已经发送到我的邮箱")
            return false;
        });
    });
</script>